package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Information;
import cn.wolfcode.trip.base.mapper.InformationMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IInformationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationServiceImpl implements IInformationService {

    @Autowired
    private InformationMapper informationMapper;



    public void delete(Long id) {
        informationMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(Information inf) {
        if (inf.getId()!=null){
            informationMapper.updateByPrimaryKey(inf);
        }else {
            informationMapper.insert(inf);
        }
    }

    public PageInfo<Information> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Information> list = informationMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    public List<Information> list() {
        return informationMapper.listAll();
    }
}
